﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Drawing;
using System.Windows.Forms;
using Styx;
using Styx.Combat.CombatRoutine;
using Styx.Helpers;
using Styx.Logic;
using Styx.Logic.Combat;
using Styx.Logic.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.Logic.POI;
using System.IO;

namespace HarmoniousVigor
{
    public class HarmoniousVigor : CombatRoutine
    {
        public static LocalPlayer Me { get { return StyxWoW.Me; } }
        public override string Name { get { return "Joystick's HarmoniousVigor " + vers; } }
        public override WoWClass Class
        {
            get
            {
                switch (Me.Class)
                {
                    case WoWClass.DeathKnight: if (enableDeathKnight) { return WoWClass.DeathKnight; } else { return WoWClass.None; }
                    case WoWClass.Druid: if (enableDruid) { return WoWClass.Druid; } else { return WoWClass.None; }
                    case WoWClass.Hunter: if (enableHunter) { return WoWClass.Hunter; } else { return WoWClass.None; }
                    case WoWClass.Mage: if (enableMage) { return WoWClass.Mage; } else { return WoWClass.None; }
                    case WoWClass.Paladin: if(enablePaladin){return WoWClass.Paladin;}else{return WoWClass.None; }
                    case WoWClass.Priest: if (enablePriest) { return WoWClass.Priest; } else { return WoWClass.None; }
                    case WoWClass.Rogue: if (enableRogue) { return WoWClass.Rogue; } else { return WoWClass.None; }
                    case WoWClass.Shaman: if (enableShaman) { return WoWClass.Shaman; } else { return WoWClass.None; }
                    case WoWClass.Warlock: if (enableWarlock) { return WoWClass.Warlock; } else { return WoWClass.None; }
                    case WoWClass.Warrior: if (enableWarrior) { return WoWClass.Warrior; } else { return WoWClass.None; }
                    default: return WoWClass.None;
                }
            }
        }
        public Version vers = new Version(0, 9, 2);
        public CharacterClass wowcharacter;
        public static string baseFolder = Path.Combine(Logging.ApplicationPath, string.Format(@"CustomClasses\HarmoniousVigor\"));
        public static string primarySpec = "none", secondarySpec = "none";
        static public HarmoniousVigorForm Form;
        static public HarmoniousVigorSettings Settings;
        static public CharacterSettings CharacterSettings; 
        

        public override bool WantButton
        {
            get
            {
                return true;
            }
        }
        public override void OnButtonPress()
        {
            Utils.nullCheckForm();
            Form.ShowDialog();
        }
        public override void Initialize()
        {
            Styx.Logic.BehaviorTree.TreeRoot.TicksPerSecond = (byte)TPS;
            Utils.setMe(Me);
            Utils.nullCheckCharacterSettings();
            Utils.nullCheckSettings();
            Utils.nullCheckForm();
            Updater.CheckForUpdate();

            switch (Me.Class)
            {
                case WoWClass.DeathKnight: wowcharacter = new DeathKnight(); break;
                case WoWClass.Druid: wowcharacter = new Druid(); break;
                case WoWClass.Hunter: wowcharacter = new Hunter(); break;
                case WoWClass.Mage: wowcharacter = new Mage(); break;
                case WoWClass.Paladin: wowcharacter = new Paladin();break;
                case WoWClass.Priest: wowcharacter = new Priest(); break;
                case WoWClass.Rogue: wowcharacter = new Rogue(); break;
                case WoWClass.Shaman: wowcharacter = new Shaman(); break;
                case WoWClass.Warlock: wowcharacter = new Warlock(); break;
                case WoWClass.Warrior: wowcharacter = new Warrior(); break;
            }
            wowcharacter.printCharacterInfo();
            wowcharacter.Initialize();
            primarySpec = wowcharacter.getPrimarySpec();
            secondarySpec = wowcharacter.getSecondarySpec();
        }
        public override void Pulse()
        {
            Stopwatch howLong = new Stopwatch();
            howLong.Start();
            wowcharacter.Pulse();
            howLong.Stop();
            Utils.DLog("Pulse took {0} ms", howLong.ElapsedMilliseconds);
        }
        public override void Combat()
        {
            Stopwatch howLong = new Stopwatch();
            howLong.Start();
            if (wowcharacter.Combat())
            {
                howLong.Stop();
                Utils.DLog("Combat took {0} ms", howLong.ElapsedMilliseconds);
                return;
            }
            else
            {
                howLong.Stop();
                Utils.DLog("Combat took {0} ms", howLong.ElapsedMilliseconds);
            }
        }
        public override void Pull()
        {
            if (wowcharacter.Pull())
                return;
        }
        public override void Rest()
        {
            if (wowcharacter.Rest())
                return;
        }
        public override bool NeedRest
        {
            get
            {
                return wowcharacter.NeedRest;
            }
        }


        //Settings
        private Boolean useFramelock
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.useFramelock;
            }
        }
        private Boolean enableDeathKnight
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.enableDeathKnight;
            }
        }
        private Boolean enableDruid
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.enableDruid;
            }
        }
        private Boolean enableHunter
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.enableHunter;
            }
        }
        private Boolean enableMage
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.enableMage;
            }
        }
        private Boolean enablePaladin
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.enablePaladin;
            }
        }
        private Boolean enablePriest
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.enablePriest;
            }
        }
        private Boolean enableRogue
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.enableRogue;
            }
        }
        private Boolean enableShaman
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.enableShaman;
            }
        }
        private Boolean enableWarlock
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.enableWarlock;
            }
        }
        private Boolean enableWarrior
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.enableWarrior;
            }
        }
        private int TPS
        {
            get
            {
                Utils.nullCheckSettings();
                return Settings.TPS;
            }
        }
    }
}
